
/*  
 * @Description: json工具类
 * Depends:
 *	jsLib/json2.js
 */

var jsonUtil;
if(! window.jsonUtil) {
	jsonUtil = {};
} else {
	throw new Error("jsonUtil has already existed!");
}

function JsonBean(requestJson){
	this.requestJson = requestJson;
}

/**
 * 将js请求对象转换为JsonBean对象传输
 * @param request
 * @returns {JsonBean}
 */
jsonUtil.toJsonBean = function(request) {
	var requestStr = this.toJsonString(request);
	var requestJson = new JsonBean(requestStr);
	
	return requestJson;
};

/**
 * 将js请求对象参数转换成json字符串
 * request：请求参数对象
 * return：转换后的json字符串
 */
jsonUtil.toJsonString = function(request) {
	if (typeof (JSON) == 'undefined') {  
		//如果浏览器不支援JSON则加载json2.js  
		$.getScript('/static/utils/json2.js');  
	}
	var requestJson = JSON.stringify(request);
	return requestJson;
};

/**
 * 将json字符串转换为js对象
 * @param jsonRslt
 * @returns
 */
jsonUtil.toJsObject = function(jsonRslt) {
	var rslt = JSON.parse(jsonRslt);
	
	return rslt;
};
